package cn.e2win.biz.comm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Formatter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.e2win.base.controller.MyException;
import cn.e2win.base.json.vo.PageMsg;
import cn.e2win.base.json.vo.WeixinUser;
import cn.e2win.biz.base.BaseController;
import cn.e2win.biz.base.BaseService;
import cn.e2win.biz.util.PropertyPlaceholder;
import cn.e2win.biz.util.StringUtils;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;


@Controller
@Scope("request")
@RequestMapping("/weixin")
public class WeiXinController extends BaseController {
	

    private static AccessToken accessToken = null;
   
    public static HashMap<String, WeixinUser> WX_MAP = new HashMap<String, WeixinUser>();
    public PageMsg pageMsg;
    

	@Override
	public BaseService initService() {
		return null;
	}
	
	

	public WeixinUser getWeixinUser(HttpServletRequest request) throws MyException {
		WeixinUser weixinUser =(WeixinUser)request.getSession().getAttribute("weixinUser"); 
		if(weixinUser == null){
			weixinUser = new WeixinUser();
			request.getSession().setAttribute("weixinUser", weixinUser); 
			//throw new MyException("请通过微信访问本网页");
		}
		return weixinUser;
	}
	
	
	@RequestMapping("token")
	@ResponseBody
	public void responseMsg(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		System.err.println("=====================be accessed!!!===========================");

		String s = "";
		try {
			request.setCharacterEncoding("UTF-8");
			response.setCharacterEncoding("UTF-8");
			Map<String, String> map = parseXml(request);
			
			if("event".equals(map.get("MsgType"))){
				if("unsubscribe".equals(map.get("Event"))){//取消关注
					
				}
				if("subscribe".equals(map.get("Event"))){//关注

				}
				if("LOCATION".equals(map.get("Event"))){//获取地址
					WeixinUser weixinUser = new WeixinUser();

					weixinUser.setOpenid(map.get("FromUserName"));
					weixinUser.setLatitude(map.get("Latitude"));
					weixinUser.setLongitude(map.get("Longitude")); 
					weixinUser.setPrecision(map.get("Precision"));
					

					String url = "http://api.map.baidu.com/geoconv/v1/?coords="+weixinUser.getLongitude()+","+weixinUser.getLatitude()+"&from=3&to=5&ak=Bp7W7v3ueD02INZO3yXquaPKBOn9Vynz";
					Map<String ,Object> jsonObject = sendGet(url, null);
					List<Map<String ,Object>> list=(List<Map<String ,Object>>)jsonObject.get("result");

					weixinUser.setBaiduX(list.get(0).get("x").toString());
					weixinUser.setBaiduY(list.get(0).get("y").toString());

					WX_MAP.put(weixinUser.getOpenid(), weixinUser);
				}

			}else if("text".equals(map.get("MsgType"))){//文本
				if("nt".equals(map.get("Content"))){
					
				}else{
					
				}
			} 

			s = "<xml>" + "<ToUserName>" + map.get("FromUserName") + "</ToUserName>" + "<FromUserName>" + map.get("ToUserName") + "</FromUserName>"
					+ "<CreateTime>12345678</CreateTime>" + "<MsgType><![CDATA[text]]></MsgType>" + "<Content><![CDATA[上一动作解析如下：\n"
					+ map.get("rString") + "]]></Content></xml>";

			//System.err.println(s);
			//response.getWriter().print(s);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	//@RequestMapping("token")
	public void token(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		getParameterMap(request);
		String TOKEN = "5kjd0z0ykx2ogtcnicnxha3kae31owul";
		String signature = request.getParameter("signature"); // 随机字符串
		String echostr = request.getParameter("echostr"); // 时间戳
		String timestamp = request.getParameter("timestamp"); // 随机数
		String nonce = request.getParameter("nonce");
		String[] str = { TOKEN, timestamp, nonce };
		Arrays.sort(str); // 字典序排序
		String bigStr = str[0] + str[1] + str[2]; // SHA1加密
		String digest = SHA1(bigStr).toLowerCase();
		System.err.println("digest=====" + digest);
		// 确认请求来至微信
		if (digest.equals(signature)) {
			try {
				System.err.println("TRUE++++++++++++++++++++++++");
				response.getWriter().print(echostr);
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			System.err.println("FALSE====================");
		}

	}

	@RequestMapping("oath")
	public String oath(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws MyException {
		String action_url = request.getParameter("action_url");
		System.err.println("action_url====" + action_url);
		WeixinUser weixinUser = getWeixinUser(request);
		if (weixinUser != null && !StringUtils.isEmpty(weixinUser.getOpenid())) {
			System.err.println("    ===============Session is not null===========================" +weixinUser.getOpenid() );
		} else {
			Object key = null;
			String code = request.getParameter("code");
			System.err.println("code====" + code);
			if (!StringUtils.isEmpty(code)) {
				JSONObject jsonObject = httpsRequest("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + PropertyPlaceholder.getProperty("weixin.APP_ID") + "&secret=" + PropertyPlaceholder.getProperty("weixin.SECRET")
						+ "&code=" + code + "&grant_type=authorization_code", "GET", null);
				if (jsonObject != null) {
					Iterator<?> it = jsonObject.keys();
					while (it.hasNext()) {
						key = it.next();
					}
				}

				JSONObject obj2 = httpsRequest("https://api.weixin.qq.com/sns/userinfo?access_token=" + jsonObject.getString("access_token")
						+ "&openid=" + jsonObject.getString("openid") + "&lang=zh_CN", "GET", null);
				if (obj2 != null) {
					Iterator<?> it = obj2.keys();
					while (it.hasNext()) {
						key = it.next();
						//System.err.println("        " + key + "====" + obj2.get(key));
					}
					initWeixinUser(weixinUser, obj2);
				}

				JSONObject obj3 = httpsRequest("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + jsonObject.getString("access_token")
						+ "&openid=" + jsonObject.getString("openid") + "&lang=zh_CN", "GET", null);
				if (obj3 != null) {
					Iterator<?> it = obj3.keys();
					while (it.hasNext()) {
						key = it.next();
						//System.err.println("        " + key + "====" + obj3.get(key));
					}
					//initWeixinUser(weixinUser, obj3);
				}
			}
		}

		
		if(action_url.indexOf(".do")>0){
			action_url = "forward:/" + action_url;
		}

		System.err.println("oath URL======" + action_url);
		return action_url;
	}
	
	private void initWeixinUser(WeixinUser weixinUser, JSONObject jsonObject){
		weixinUser.setOpenid(jsonObject.getString("openid"));
		weixinUser.setNickname(jsonObject.getString("nickname"));
		weixinUser.setSex(jsonObject.getString("sex"));
		weixinUser.setCity(jsonObject.getString("city"));
		weixinUser.setCountry(jsonObject.getString("country"));
		weixinUser.setProvince(jsonObject.getString("province"));
		weixinUser.setLanguage(jsonObject.getString("language"));
		weixinUser.setHeadimgurl(jsonObject.getString("headimgurl"));
		if(WX_MAP.containsKey(weixinUser.getOpenid())){
			WeixinUser temp = WX_MAP.get(weixinUser.getOpenid());
			weixinUser.setBaiduX(temp.getBaiduX());
			weixinUser.setBaiduY(temp.getBaiduY());
			weixinUser.setLatitude(temp.getLatitude());
			weixinUser.setLongitude(weixinUser.getLongitude());
			//WX_MAP.remove(weixinUser.getOpenid());
			
			System.err.println("session 中 得到====" + weixinUser.getOpenid() + " ===== " + weixinUser.getBaiduX() + " ======  " + weixinUser.getBaiduY());
		}
	}
	
	
	
	
	
    /** 
     * 发送模板消息 
     * @param accessToken 
     * @param jsonData 
     */  
    public static void sendTemplateMsg(String accessToken,String jsonData){
    	String tplMsgSendUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
    	System.err.println("msg=====" + jsonData);
        String requestUrl=tplMsgSendUrl.replace("ACCESS_TOKEN", accessToken);  
        JSONObject jsonObject = httpsRequest(requestUrl, "POST", jsonData);  
        if(jsonObject!=null){  
            if("0".equals(jsonObject.getString("errcode"))){  
                System.out.println("发送模板消息成功！");  
            }else{  
                System.out.println(jsonObject.getString("errcode"));  
                System.out.println(jsonObject.getString("errmsg"));  
            }  
        }  
    }  

    /** 
     * 发送模板消息 
     * @param accessToken 
     * @param jsonData 
     */  
    private void createMenu(String accessToken,String jsonData){
    	String createMenuUrl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
        String requestUrl=createMenuUrl.replace("ACCESS_TOKEN", accessToken);  
        JSONObject jsonObject = httpsRequest(requestUrl, "GET", jsonData);  
        if(jsonObject!=null){  
            if("0".equals(jsonObject.getString("errcode"))){  
                System.out.println("创建菜单成功！");  
            }else{  
                System.out.println(jsonObject.getString("errcode"));  
                System.out.println(jsonObject.getString("errmsg"));  
            }  
        }  
    }  
	
	
    /** 
     * 发起https请求并获取结果 
     *  
     * @param requestUrl 请求地址 
     * @param requestMethod 请求方式（GET、POST） 
     * @param outputStr 提交的数据 
     * @return JSONObject(通过JSONObject.getString(key)的方式获取json对象的属性值) 
     */  
    public static JSONObject httpsRequest(String requestUrl, String requestMethod, String outputStr) {  
        JSONObject jsonObject = null;  
        StringBuffer buffer = new StringBuffer();  
        try {  
            // 创建SSLContext对象，并使用我们指定的信任管理器初始化  
            TrustManager[] tm = { new MyX509TrustManager() };  
            SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");  
            sslContext.init(null, tm, new java.security.SecureRandom());  
            // 从上述SSLContext对象中得到SSLSocketFactory对象  
            SSLSocketFactory ssf = sslContext.getSocketFactory();  
      
            URL url = new URL(requestUrl);  
            HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();  
            httpUrlConn.setSSLSocketFactory(ssf);  
      
            httpUrlConn.setDoOutput(true);  
            httpUrlConn.setDoInput(true);  
            httpUrlConn.setUseCaches(false);  
            // 设置请求方式（GET/POST）  
            httpUrlConn.setRequestMethod(requestMethod);  
      
            if ("GET".equalsIgnoreCase(requestMethod))  
                httpUrlConn.connect();  
      
            // 当有数据需要提交时  
            if (null != outputStr) {  
                OutputStream outputStream = httpUrlConn.getOutputStream();  
                // 注意编码格式，防止中文乱码  
                outputStream.write(outputStr.getBytes("UTF-8"));  
                outputStream.close();  
            }  
      
            // 将返回的输入流转换成字符串  
            InputStream inputStream = httpUrlConn.getInputStream();  
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");  
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);  
      
            String str = null;  
            while ((str = bufferedReader.readLine()) != null) {  
                buffer.append(str);  
            }  
            bufferedReader.close();  
            inputStreamReader.close();  
            // 释放资源  
            inputStream.close();  
            inputStream = null;  
            httpUrlConn.disconnect();  
            jsonObject = JSONObject.fromObject(buffer.toString());  
        } catch (ConnectException ce) {  
        } catch (Exception e) {  
        }  
        return jsonObject;  
    }  
	
	
	
	
	
	
	
	
	


	public static Map<String, String> parseXml(HttpServletRequest request) throws Exception {
		// 将解析结果存储在HashMap中
		Map<String, String> map = new HashMap<String, String>();
		String rString = "";
		// 从request中取得输入流
		InputStream inputStream = request.getInputStream();
		// 读取输入流
		SAXReader reader = new SAXReader();
		Document document = reader.read(inputStream);
		// 得到xml根元素
		Element root = document.getRootElement();
		// 得到根元素的所有子节点
		List<Element> elementList = root.elements();
		System.err.println("/n/n/n=================================");
		// 遍历所有子节点
		for (Element e : elementList) {
			System.err.println(e.getName() + " == " + e.getText());
			rString = rString + "\n" + e.getName() + " : " + e.getText();
			map.put(e.getName(), e.getText());
		}
		map.put("rString", rString);
		System.err.println("=================================/n/n/n");
		// 释放资源
		inputStream.close();
		inputStream = null;

		return map;
	}

	public static String SHA1(String decript) {
		try {
			MessageDigest digest = MessageDigest.getInstance("SHA-1");
			digest.update(decript.getBytes());
			byte messageDigest[] = digest.digest();
			// Create Hex String
			StringBuffer hexString = new StringBuffer();
			// 字节数组转换为 十六进制 数
			for (int i = 0; i < messageDigest.length; i++) {
				String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
				if (shaHex.length() < 2) {
					hexString.append(0);
				}
				hexString.append(shaHex);
			}
			return hexString.toString();

		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return "";
	}

	protected Map<String, Object> getParameterMap(HttpServletRequest request) {
		Map<String, Object> pathMap = new HashMap<String, Object>(20);
		Enumeration<?> enum_term = request.getParameterNames();
		while (enum_term.hasMoreElements()) {
			String paramName = (String) enum_term.nextElement();
			if (request.getParameterValues(paramName).length > 1) {
				pathMap.put(paramName, request.getParameterValues(paramName));
				System.err.println(paramName + "  []======" + request.getParameterValues(paramName));
			} else {
				pathMap.put(paramName, request.getParameter(paramName));
				System.err.println(paramName + "======" + request.getParameter(paramName));
			}
		}
		return pathMap;
	}

	public String getIpAddr(HttpServletRequest request) {
		String ip = request.getHeader(" x-forwarded-for ");
		if (ip == null || ip.length() == 0 || " unknown ".equalsIgnoreCase(ip)) {
			ip = request.getHeader(" Proxy-Client-IP ");
			System.err.println("1111=" + ip);

		}
		if (ip == null || ip.length() == 0 || " unknown ".equalsIgnoreCase(ip)) {
			ip = request.getHeader(" WL-Proxy-Client-IP ");
			System.err.println("2222=" + ip);
		}
		if (ip == null || ip.length() == 0 || " unknown ".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
			System.err.println("3333=" + ip);
		}
		return ip;
	}

    
	public String getAccessToken() {
		Long now = System.currentTimeMillis();
    	if(accessToken==null){
    		initAccessToken();
    	}else if(accessToken!=null && now>accessToken.getExpiresTime()){
    		System.err.println("超时了===============" + now + "============" + accessToken.getExpiresTime());
    		initAccessToken();
    	}else{
    		System.err.println("未超时===============" + now + "============" + accessToken.getExpiresTime());
    	}
    	return accessToken.getToken();  
    }  
	
    private void initAccessToken(){
    	String requestUrl = PropertyPlaceholder.getProperty("weixin.access_token_url").replace("APPID", PropertyPlaceholder.getProperty("weixin.APP_ID")).replace("APPSECRET", PropertyPlaceholder.getProperty("weixin.SECRET"));  
        JSONObject jsonObject = httpsRequest(requestUrl, "GET", null);  
        // 如果请求成功  
        if (null != jsonObject) { 
            try {  
                accessToken = new AccessToken();  
                accessToken.setToken(jsonObject.getString("access_token"));  
                accessToken.setExpiresIn(jsonObject.getInt("expires_in"));  
            } catch (JSONException e) {  
                accessToken = null;  
                // 获取token失败  
                //log.error("获取token失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));  
            }  
        }  
    }
	
	

	public static void main(String[] args) throws Exception {
		System.out.println("=========1获取token=========");
		WeiXinController controller = new WeiXinController();
		
		
		
		String jsonText = "";
		
		 String menuText = "{\"button\":[" +
		  		"{\"type\":\"view\",\"name\":\"腾农&测试\",\"url\":\"" +
  				"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + PropertyPlaceholder.getProperty("weixin.APP_ID") +
  				"&redirect_uri=http://tn.weejin.cn/weixin/oath.do%3Faction_url=m/main.do" +
  				"&response_type=code" +
  				"&scope=snsapi_userinfo" +
  				"&state=1#wechat_redirect\"" +
  				"}";
		 
		 menuText="{\"button\":[ "
			 	+ "{\"type\":\"view\",\"name\":\"合伙人\",\"url\":"
			 	
		 			+ "\"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" 
		 			+ PropertyPlaceholder.getProperty("weixin.APP_ID")
		 			+ "&redirect_uri=http://hhr.whzxqy.cn/weixin/oath.do%3Faction_url=m/dsMain.do" 
		 			+ "&response_type=code" 
		 			+ "&scope=snsapi_userinfo" 
		 			+ "&state=1#wechat_redirect\"" 
			 	
		 		+ "}, "
			 	+ "{\"type\":\"view\",\"name\":\"最新活动\",\"url\":"
			 	
		 			+ "\"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" 
		 			+ PropertyPlaceholder.getProperty("weixin.APP_ID")
		 			+ "&redirect_uri=http://hhr.whzxqy.cn/weixin/oath.do%3Faction_url=m/activityMain.do" 
		 			+ "&response_type=code" 
		 			+ "&scope=snsapi_userinfo" 
		 			+ "&state=1#wechat_redirect\"" 
			 	
		 		+ "}, "
		 		+ "{\"name\":\"个人中心\",\"sub_button\":["
		 			+ "{\"type\":\"view\", \"name\":\"管理平台\", \"url\":"
		 			+ "\"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" 
		 			+ PropertyPlaceholder.getProperty("weixin.APP_ID")
		 			+ "&redirect_uri=http://hhr.whzxqy.cn/weixin/oath.do%3Faction_url=m/index.do" 
		 			+ "&response_type=code" 
		 			+ "&scope=snsapi_userinfo" 
		 			+ "&state=1#wechat_redirect\"" 
		 			+ "}"
	 			+ "]"
	 			+ "}"
	 			+ "]}";
		 controller.createMenu(controller.getAccessToken(),menuText);
		 /*
		 
		//会员充值成功通知
		jsonText="{\"touser\":\"ocd8vswfhC_mdiok3nyMtsGc9s3o\"," +
		    		"\"template_id\":\"NAT0T43X9As12xXFadP4Pl2iFsydU5jNqKTuIzlWyXU\"," +
		    		"\"url\":\"http://www.ggzzapp.com\"," +
		    		"\"topcolor\":\"#FF0000\"," +
		    		"\"data\":{" +
		    			"\"first\": {" +
		    				"\"value\":\"亲爱的会员 杜乾坤您好，\\n感谢您在【车焦点】充值！\\n您本次的充值信息如下：\\n\"," +
		    				"\"color\":\"#173177\"}," +
	    				"\"keyword1\": {" +					//充值金额
	    					"\"value\":\"128.00元\"," +
	    					"\"color\":\"\"}," +
		    			"\"keyword2\": {" +					//充值门店
		    				"\"value\":\"【车焦点汽车美容店】\"," +
		    				"\"color\":\"\"}," +
	    				"\"keyword3\": {" +					//当前余额
	    					"\"value\":\"1000元\"," +
	    					"\"color\":\"\"}," +
		    			
	    				"\"remark\": {" +
	    					"\"value\":\"" +
	    					"获得积分：128分\\n" +
	    					"当前积分：1256分\\n" +	    					
	    					"消费单号：150387654\\n" +
	    					"消费时间：2015-03-30 13:23:30\\n" +
	    					
	    					"\\n点击详情查看充值明细！\"," +
	    					"\"color\":\"\"}}}";
		
			//会员消费成功通知
		  jsonText="{\"touser\":\"ocd8vs1yeQc7WOra16xHT_qFngRg\"," +
		    		"\"template_id\":\"obezQhrxFTdpYv06gZ41uIaG3VUlLk2xvhCNkdsosjM\"," +
		    		"\"url\":\"http://www.ggzzapp.com\"," +
		    		"\"topcolor\":\"#FF0000\"," +
		    		"\"data\":{" +
		    			"\"first\": {" +
		    				"\"value\":\"亲爱的会员 杜乾坤您好，\\n感谢您在【车焦点】消费！\\n您本次的消费信息如下：\\n\"," +
		    				"\"color\":\"#173177\"}," +
	    				"\"keyword1\": {" +					//消费金额
	    					"\"value\":\"128.00元\"," +
	    					"\"color\":\"\"}," +
		    			"\"keyword2\": {" +					//获得积分
		    				"\"value\":\"128分\"," +
		    				"\"color\":\"\"}," +
	    				"\"keyword3\": {" +					//消费门店
	    					"\"value\":\"【车焦点汽车美容店】\"," +
	    					"\"color\":\"\"}," +
		    			"\"keyword4\": {" +					//当前余额
		    				"\"value\":\"872元\"," +
		    				"\"color\":\"\"}," +
		    			"\"keyword5\": {" +					//当前积分
		    				"\"color\":\"\"}," +
	    				"\"remark\": {" +
	    					"\"value\":\"" +
	    						"消费单号：150387654\\n" +
	    						"消费时间：2015-03-30 13:23:30\\n" +
	    						"\\n点击详情查看消费明细！\"," +
	    						"\"color\":\"\"}}}";

		  
			//计次消费通知
		  jsonText="{\"touser\":\"ocd8vswfhC_mdiok3nyMtsGc9s3o\"," +
		    		"\"template_id\":\"6eR8SzR6-XCf-nYAiQoZXqNRHcXtNbwRUPKLJhoBvdE\"," +
		    		"\"url\":\"http://www.ggzzapp.com\"," +
		    		"\"topcolor\":\"#FF0000\"," +
		    		"\"data\":{" +
		    			"\"first\": {" +
		    				"\"value\":\"亲爱的会员 杜乾坤您好，\\n感谢您在【车焦点】消费！\\n您本次的消费信息如下：\\n\"," +
		    				"\"color\":\"#173177\"}," +
	    				"\"keyword1\": {" +					//扣次项目
	    					"\"value\":\"普通洗车(小型车)\"," +
	    					"\"color\":\"\"}," +
		    			"\"keyword2\": {" +					//扣除次数
		    				"\"value\":\"1次\"," +
		    				"\"color\":\"\"}," +
	    				"\"keyword3\": {" +					//消费门店
	    					"\"value\":\"【车焦点汽车美容店】\"," +
	    					"\"color\":\"\"}," +
	    				"\"keyword4\": {" +					//剩余次数
	    					"\"value\":\"9次\"," +
	    					"\"color\":\"\"}," +
		    			
	    				"\"remark\": {" +
	    					"\"value\":\"" +		
	    					"消费单号：150387654\\n" +
	    					"消费时间：2015-03-30 13:23:30\\n" +
	    					
	    					"\\n点击详情查看消费明细！\"," +
	    					"\"color\":\"\"}}}";
		  

		  
			//购买计次成功通知
		  jsonText="{\"touser\":\"ocd8vswfhC_mdiok3nyMtsGc9s3o\"," +
		    		"\"template_id\":\"kwqvDsWSM9HpDG1mqYsdAVrTxEbupl3yQ-UiOT0eMJw\"," +
		    		"\"url\":\"http://www.ggzzapp.com\"," +
		    		"\"topcolor\":\"#FF0000\"," +
		    		"\"data\":{" +
		    			"\"first\": {" +
		    				"\"value\":\"亲爱的会员 杜乾坤您好，\\n感谢您在【车焦点】充值！\\n您本次的充值信息如下：\\n\"," +
		    				"\"color\":\"#173177\"}," +
	    				"\"keyword1\": {" +					//计次项目
	    					"\"value\":\"普通洗车(小型车)\"," +
	    					"\"color\":\"\"}," +
		    			"\"keyword2\": {" +					//购买次数
		    				"\"value\":\"1次\"," +
		    				"\"color\":\"\"}," +
	    				"\"keyword3\": {" +					//操作门店
	    					"\"value\":\"【车焦点汽车美容店】\"," +
	    					"\"color\":\"\"}," +
	    				"\"keyword4\": {" +					//剩余次数
	    					"\"value\":\"9次\"," +
	    					"\"color\":\"\"}," +
		    			
	    				"\"remark\": {" +
	    					"\"value\":\"" +		
	    					"消费单号：150387654\\n" +
	    					"消费时间：2015-03-30 13:23:30\\n" +
	    					
	    					"\\n点击详情查看充值明细！\"," +
	    					"\"color\":\"\"}}}";

			//微信绑定成功通知
		  jsonText="{\"touser\":\"ocd8vswfhC_mdiok3nyMtsGc9s3o\"," +
		    		"\"template_id\":\"in-x8520IGFLkyNyTOXKD1DnJlwpkNFrxOWOwD6uBfg\"," +
		    		"\"url\":\"http://www.ggzzapp.com\"," +
		    		"\"topcolor\":\"#FF0000\"," +
		    		"\"data\":{" +
		    			"\"first\": {" +
		    				"\"value\":\"亲爱的会员 杜乾坤您好，\\n您已经成功绑定你在【车焦点汽车美容店】的会员卡，相关信息如下：\\n\"," +
		    				"\"color\":\"#173177\"}," +
	    				"\"keyword1\": {" +					//微信ID
	    					"\"value\":\"robindu2012\"," +
	    					"\"color\":\"\"}," +
		    			"\"keyword2\": {" +					//绑定账号
		    				"\"value\":\"CJD-10008888\"," +
		    				"\"color\":\"\"}," +
	    				"\"keyword3\": {" +					//开通功能
	    					"\"value\":\"订单动态跟踪、还款提醒、免密登录、消费充值记录，明细及其它功能等等\"," +
	    					"\"color\":\"\"}," +

		    			
	    				"\"remark\": {" +
	    					"\"value\":\"" +		
	    					"绑定门店：【车焦点汽车美容店】\\n" +
	    					"绑定时间：2015-03-30 13:23:30\\n" +
	    					"请注意：绑定帐号即为您的会员卡号！\\n" +
	    					"\\n点击详情查详细信息！\"," +
	    					"\"color\":\"\"}}}";

			//消费通知
		  jsonText="{\"touser\":\"ocd8vs1yeQc7WOra16xHT_qFngRg\"," +
		    		"\"template_id\":\"NlyC0xI0Ii9gzYputD80ou4OfFwADXTToGrhgxeKZ0M\"," +
		    		"\"url\":\"http://www.ggzzapp.com\"," +
		    		"\"topcolor\":\"#FF0000\"," +
		    		"\"data\":{" +
	    				"\"productType\": {" +					//微信ID
	    					"\"value\":\"消费门店\"," +
	    					"\"color\":\"\"}," +
		    			"\"name\": {" +					//消费门店
		    				"\"value\":\"【车焦点汽车美容店】\"," +
		    				"\"color\":\"\"}," +
	    				"\"time\": {" +					//消费时间
	    					"\"value\":\"2015-03-30 13:23:30\"," +
	    					"\"color\":\"\"}," +

	    				"\"remark\": {" +
		    				"\"value\":\"\\n亲爱的会员 杜乾坤 您好，您本次消费信息如下：\\n\\n" +
	    					"消费总额：400.00元\\n" +
	    					"会员折扣：100.00元\\n" +
	    					"会员卡抵扣：300.00元\\n" +
	    					"折后优惠：0.00元\\n" +
	    					"实付现金：0.00元\\n" +
	    					//"获得积分：128分\\n" +
	    					//"当前积分：1256分\\n" +	
	    					"会员卡号：CJD-1000001\\n" +
	    					"业务单号：150387654\\n\\n" +		
	    					
	    					"感谢您的惠顾!\\n" +
	    					"点击详情查看本次消费明细及会员卡余额！\"," +
	    					"\"color\":\"\"}}}";			
		  //充值成功通知*/
		  jsonText="{\"touser\":\"ocd8vs1yeQc7WOra16xHT_qFngRg\"," +
		    		"\"template_id\":\"vMi_a8jpXVBABqYyiZeTMT-28R5WW4ZhST-hoknrKZo\"," +
		    		"\"url\":\"http://www.ggzzapp.com\"," +
		    		"\"topcolor\":\"#FF0000\"," +
		    		"\"data\":{" +
	    			"\"first\": {" +
	    				"\"value\":\"亲爱的会员 杜乾坤 您好，您本次充值信息如下：\\n\\n" +
	    				"充值门店：【车焦点汽车美容店】\"," +
	    				"\"color\":\"\"}," +
    				"\"keyword1\": {" +					//本次充值
    					"\"value\":\"128.00元\"," +
    					"\"color\":\"\"}," +
    				"\"keyword2\": {" +					//充值时间
    					"\"value\":\"2015-03-30 13:23:30\"," +
    					"\"color\":\"\"}," +
	    			
    				"\"remark\": {" +
    					"\"value\":\"" +
    					//"获得积分：128分\\n" +
    					//"当前积分：1256分\\n" +	    	
    					"会员卡号：CJD-1000001\\n" +				
    					"业务单号：150387654\\n\\n" +

						"感谢您的惠顾!\\n" +
    					"点击详情查看本次充值明细及会员卡余额！\"," +
    					"\"color\":\"\"}}}";
		  
		//sendTemplateMsg(controller.getAccessToken(), jsonText);
			  
		
	}
	

	   

}